<template>
  <div class="customerFile">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">客户档案管理</span>
        <el-button style="float: right;" type="primary" @click="dialogOpen('add')" v-if="USER.auth.indexOf('business_customerFile_add')!==-1">新增客户档案</el-button>
      </div>
      <s-table
        :table="table" ref="table" @http="tableWatch">
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="table.multiSelect">
          <el-row>
            <el-button size="small" type="warning" @click="tableActive('')" v-if="USER.auth.indexOf('business_customerFile_enable')!==-1">多选启用</el-button>
            <el-button size="small" type="danger" @click="tableDelete('')" v-if="USER.auth.indexOf('business_customerFile_disable')!==-1">多选禁用</el-button>
          </el-row>
        </el-form-item>
        <el-form-item label="客户编号" prop="khbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_khbh"
                    placeholder="客户编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="客户类型" prop="khlx">
          <el-select v-model="autoVue_table_khlx" placeholder="请选择">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in CUSTOMERFILE.khlx"
              :key="item.dictionaryid"
              :label="item.value"
              :value="item.dictionaryid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户名称" prop="khmc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_khmc"
                    placeholder="客户名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="激活状态" prop="sfjh">
          <el-select v-model="autoVue_table_sfjh"
                     placeholder="是否激活">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              label="未激活"
              value="0"></el-option>
            <el-option
              label="已激活"
              value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="120">
          <template scope="s">
            <div v-if="s.row.sfjh === '1'">
              <el-button type="info" icon="search" size="mini" @click="tableSearch(s.row)" v-if="USER.auth.indexOf('business_customerFile_search')!==-1"></el-button>
              <el-button type="success" icon="edit" size="mini" @click="dialogOpen('PUT', s.row)" v-if="USER.auth.indexOf('business_customerFile_edit')!==-1"></el-button>
              <el-button type="danger" size="mini" @click="tableDelete(s.row)" v-if="USER.auth.indexOf('business_customerFile_disable')!==-1"><i class="fa fa-lock" aria-hidden="true"></i></el-button>
            </div>
            <div v-else>
              <el-button type="warning" size="mini" @click="tableActive(s.row)" v-if="USER.auth.indexOf('business_customerFile_enable')!==-1"><i class="fa fa-unlock" aria-hidden="true"></i></el-button>
            </div>
          </template>
        </el-table-column>
      </s-table>
    </el-card>
    <s-dialog :dialog="dialog" :close="dialogInit">
      <p slot="title">{{dialog.title}}客户档案</p>
      <s-form :form="formDialog1" ref="formDialog1">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item label="货主名称">
              <div class="s-content">
                <el-tag type="success">{{USER.hz[0]? USER.hz[0].show_hzid : '暂无货主'}}</el-tag>
              </div>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="khbh" label="客户编号" >
              <el-input
                type="text"
                v-model="formDialog1.khbh"
                placeholder="客户编号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="khmc" label="客户名称">
              <el-input
                type="text"
                :disabled="dialog.title == '修改'"
                v-model="formDialog1.khmc"
                placeholder="客户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="khlx" label="客户类型">
              <el-select v-model="formDialog1.khlx" placeholder="请选择">
                <el-option
                  v-for="item in CUSTOMERFILE.khlx"
                  :key="item.dictionaryid"
                  :label="item.value"
                  :value="item.dictionaryid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="china" label="省/市">
              <el-cascader
                filterable
                change-on-select
                expand-trigger="hover"
                :options="CUSTOMERFILE.china"
                @change="dialogChangeLx"
                v-model="formDialog1.china">
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="lxid" label="路线">
              <el-select v-model="formDialog1.lxid"
                         :disabled="formDialog1.china.length != 2"
                         filterable
                         remote
                         placeholder="请选择路线"
                         :remote-method="dialogRemoteLx">
                <el-option
                  v-for="item in dialog.lxid"
                  :key="item.id"
                  :label="item.xlmc"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="dz" label="详细地址">
              <el-input
                type="text"
                v-model="formDialog1.dz"
                placeholder="详细地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="lxrxm" label="联系人姓名">
              <el-input
                type="text"
                v-model="formDialog1.lxrxm"
                placeholder="联系人姓名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="lxrdh" label="联系电话">
              <el-input
                type="text"
                v-model="formDialog1.lxrdh"
                placeholder="联系电话"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" type="success" @click="dialogSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogShr" :close="dialogShrInit" :closeTip="false">
      <p slot="title">{{dialogShr.title}}</p>
      <el-card>
        <div slot="header" class="clearfix">
          <el-form>
            <el-row>
              <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                <el-form-item label="详细地址">
                  <el-input
                    type="text"
                    v-model="autoVue_tableShr_xxdz"
                    placeholder="详细地址"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item label="联系人">
                  <el-input
                    type="text"
                    v-model="autoVue_tableShr_lxr"
                    placeholder="联系人"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item label="可用操作">
                  <div class="s-content">
                    <el-button type="primary" @click="dialogShrAddOpen('add')">新增收货地址</el-button>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <s-table :table="tableShr" :pagination="false" :expand="false" :index="true" ref="tableShr" @http="tableWatch">
          <el-table-column
            fixed="right"
            align="center"
            slot="operation"
            class-name="operationMore"
            label="操作"
            width="120">
            <template scope="s">
              <div v-if="s.row.sfyx === '1'">
                <el-button type="success" icon="edit" size="mini" @click="dialogShrAddOpen('put', s.row)"></el-button>
                <el-button type="info" size="mini" v-if="s.row.sfmr === '0'" @click="tableShrSetDefault(s.row)" icon="star-on"></el-button>
                <el-button type="info" size="mini" v-else @click="tableShrCancelDefault(s.row)" icon="star-off"></el-button>
                <el-button type="danger" size="mini" @click="tableShrDelete(s.row)"><i class="fa fa-lock" aria-hidden="true"></i></el-button>
              </div>
              <div v-else>
                <el-button type="info" size="mini" @click="tableShrActive(s.row)"><i class="fa fa-unlock" aria-hidden="true"></i></el-button>
              </div>
            </template>
          </el-table-column>
        </s-table>
      </el-card>
      <el-button slot="footer" @click="dialogShrSave">好</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogShrAdd" :close="dialogShrAddInit">
      <p slot="title">{{dialogShrAdd.title}}收货地址</p>
      <s-form :form="formDialogShrAdd" ref="formDialogShrAdd">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="china" label="省/市">
              <el-cascader
                filterable
                change-on-select
                expand-trigger="hover"
                :options="CUSTOMERFILE.china"
                v-model="formDialogShrAdd.china">
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="xxdz" label="详细地址">
              <el-input
                type="text"
                v-model="formDialogShrAdd.xxdz"
                placeholder="详细地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="lxr" label="联系人姓名">
              <el-input
                type="text"
                v-model="formDialogShrAdd.lxr"
                placeholder="联系人姓名"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="lxdh" label="联系人电话">
              <el-input
                type="text"
                v-model="formDialogShrAdd.lxdh"
                placeholder="联系人电话"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogShrAddSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogCyr" :closeTip="false" :close="dialogCysInit">
      <p slot="title">{{dialogCyr.title}}</p>
      <el-card>
        <div slot="header" class="clearfix">
          <el-form>
            <el-row>
              <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                <el-form-item label="车牌号">
                  <el-input
                    type="text"
                    v-model="autoVue_tableCyr_cph"
                    placeholder="车牌号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item label="司机电话">
                  <el-input
                    type="text"
                    v-model="autoVue_tableCyr_sjdh"
                    placeholder="司机电话"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item label="可用操作">
                  <div class="s-content">
                    <el-button type="primary" @click="dialogCyrAddOpen('add')">新增车辆</el-button>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <s-table :table="tableCyr" :pagination="false" ref="tableCyr" :expand="false" :index="true"  @http="tableWatch">
          <el-table-column
            fixed="right"
            align="center"
            slot="operation"
            class-name="operationMore"
            label="操作"
            width="80">
            <template scope="s">
              <div v-if="s.row.sfyx === '1'">
                <el-button type="success" icon="edit" size="mini" @click="dialogCyrAddOpen('put', s.row)"></el-button>
                <el-button type="danger" size="mini" @click="tableCyrDelete(s.row)"><i class="fa fa-lock" aria-hidden="true"></i></el-button>
              </div>
              <div v-else>
                <el-button type="info" size="mini" @click="tableCyrActive(s.row)"><i class="fa fa-unlock" aria-hidden="true"></i></el-button>
              </div>
            </template>
          </el-table-column>
        </s-table>
      </el-card>
      <el-button slot="footer" @click="dialogCyrSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogCyrAdd" :close="dialogCyrAddInit">
      <p slot="title">{{dialogCyrAdd.title}}承运车辆</p>
      <s-form :form="formDialogCyrAdd" ref="formDialogCyrAdd">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="cph" label="车牌号">
              <el-input
                type="text"
                v-model="formDialogCyrAdd.cph"
                placeholder="车牌号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="sjxm" label="司机姓名">
              <el-input
                type="text"
                v-model="formDialogCyrAdd.sjxm"
                placeholder="司机姓名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="sjdh" label="司机电话">
              <el-input
                type="text"
                v-model="formDialogCyrAdd.sjdh"
                placeholder="司机电话"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogCyrAddSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogCangku" :close="dialogCangkuInit">
      <p slot="title">{{dialogCangku.title}}</p>
      <el-tree
        :data="dialogCangku.tree.data"
        :ref="dialogCangku.tree.ref"
        :props="{
          children: 'children',
          label: 'name'
        }"
        node-key="id"
        :default-checked-keys="dialogCangku.tree.ids"
        show-checkbox>
      </el-tree>
      <el-button slot="footer" @click="dialogCangkuSave">保存</el-button>
    </s-dialog>
  </div>
</template>
<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';
  import {China} from '~/config';
  function __form () {
    return {
      khbh: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      khmc: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      khlx: { value: '', rule: [ 'vNull__change' ], cRemarks: '' },
      lxid:
        { value: '',
          rule: [ 'vNull' ],
          cRemarks: 'wmsCustomerFile/baseSelectLine' },
      china:
        { value: [],
          rule: [ 'vNullArray2__change' ] },
      dz: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      lxrdh: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      lxrxm: { value: '', rule: [ 'vNull' ], cRemarks: '' },
    };
  }
  function __formShrAdd () {
    return {
      china: {
        value: [],
        rule: ['vNullArray2__change'],
        cRemarks: '/wmsAddressDictionary/province',
      },
      xxdz: {value: '', rule: ['vNull'], cRemarks: ''},
      lxr: {value: '', rule: ['vNull'], cRemarks: ''},
      lxdh: {value: '', rule: ['vNull'], cRemarks: ''},
    };
  }
  function __formCyrAdd () {
    return {
      cph: {value: '', rule: ['vNull'], cRemarks: ''},
      sjxm: {value: '', rule: ['vNull'], cRemarks: ''},
      sjdh: {value: '', rule: ['vNull'], cRemarks: ''},
    };
  }
  export default AutoVue({
    name: 'business_customerFile-FEcarWms',
    store: ['DICTIONARY_customerFile', 'CUSTOMERFILE', 'USER'],
    data: {
      table: {
        column: [
          {
            label: '客户编号',
            prop: 'khbh',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '客户名称',
            prop: 'khmc',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '客户类型',
            prop: 'show_khlx',
            minWidth: '0px',
            elTag: {
              filterType: function (value) {
                return 'primary';
              },
            },
            cRemarks: '',
            search: true,
          },
          {
            label: '所在省',
            prop: 'sheng',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '所在市',
            prop: 'shi',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '客户地址',
            prop: 'dz',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '联系人',
            prop: 'lxrxm',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '联系电话',
            prop: 'lxrdh',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '是否激活',
            prop: 'sfjh',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '货主名称',
            prop: 'hzmc',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          }],
        url: '/wmsCustomerFile/list',
        key: 'id',
        tableColumn: 6,
      },
      formDialog1: __form(),
      dialog: {
        title: '新增',
        row: {},
        size: 'large',
        id: 0,
        lxid: [],
        shengId: 0,
        shiId: [],
        activeName: '1',
      },

      dialogShr: {
        title: '收货地址管理',
        row: {},
        size: 'large',
      },
      tableShr: {
        column: [
          {
            label: '省',
            prop: 'sheng',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '城市',
            prop: 'shi',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '详细地址',
            prop: 'xxdz',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '联系人',
            prop: 'lxr',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '联系电话',
            prop: 'lxdh',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
        ],
        url: '/wmsCustomerFileConsignee/list',
        key: 'id',
        tableColumn: 5,
      },
      dialogShrAdd: {
        title: '新增',
        row: {},
      },
      formDialogShrAdd: __formShrAdd(),

      dialogCyr: {
        title: '承运车辆管理',
        row: {},
        size: 'large',
      },
      tableCyr: {
        column: [{
          label: '车牌号',
          prop: 'cph',
          minWidth: '0px',
          cRemarks: '',
          search: true,
        },
        {
          label: '司机姓名',
          prop: 'sjxm',
          minWidth: '0px',
          cRemarks: '',
          search: false,
        },
        {
          label: '司机电话',
          prop: 'sjdh',
          minWidth: '0px',
          cRemarks: '',
          search: true,
        },
        {
          label: '激活状态',
          prop: 'show_sfyx',
          minWidth: '0px',
          cRemarks: '',
          search: false,
        },
        ],
        url: '/wmsCustomerFileCarrier/list',
        tableColumn: 4,
        key: 'id',
      },
      dialogCyrAdd: {
        title: '新增',
        row: {},
      },
      formDialogCyrAdd: __formCyrAdd(),

      dialogCangku: {
        title: '所属仓库管理',
        row: {},
        tree: {
          data: [],
          ref: 'cangkuTree',
          ids: [],
        },
        size: 'large',
      },
      tableCangku: {
        column: [{
          label: '仓库名称',
          prop: 'name',
          minWidth: '0px',
          cRemarks: '',
          search: false,
        },
        {
          label: '仓库地址',
          prop: 'remark',
          minWidth: '0px',
          cRemarks: '',
          search: false,
        }],
        url: '/wmsCustomerFileWarehouse/list',
        tableColumn: 2,
      },
    },
    transition: 'slide-fade',
    methods: {
      tableSearch (row) {
        let stepDialog = {};
        switch (row.khlx) {
        case '0':
          stepDialog = 'dialogShr';
          break;
        case '1':
          stepDialog = 'dialogCyr';
          break;
        case '2':
          stepDialog = 'dialogCangku';
          break;
        }
        this[stepDialog + 'Open']('put', row);
      },
      tableDelete (row) {
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将禁用客户档案。', '确认禁用？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsCustomerFile/cancel', {
                ids,
              });
              this.tableWatch('table');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {});
      },
      tableActive (row) {
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将启用客户档案。', '确认启用？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsCustomerFile/activation', {
                ids,
              });
              this.tableWatch('table');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {});
      },

      dialogInit () {
        this.formDialog1 = {
          ...this.formDialog1,
          ...this.ObjectClone(__form()),
        };
        this.resetFields('formDialog1');
      },
      async dialogOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        await AutoPromise([
          async () => {
            if (!this.DICTIONARY_customerFile) {
              await this.USE('DICTIONARY_customerFile');
            }
          },
          async () => {
            /* 此处的模糊查询 mc必须要传 */
            this.dialog.lxid = await this.post('/wmsCustomerFile/baseSelectLine', {mc: ''});
          },
        ]);
        switch (type) {
        case 'ADD':
          this.dialog.title = '新增';
          break;
        case 'PUT':
          this.dialog.title = '修改';
          row.china = [row.sheng, row.shi];
          this.formDialog1 = {
            ...this.formDialog1,
            ...this.ObjectClone(__form(), row),
          };
          this.dialog.row = row;
          break;
        }
        this.dialog.visible = true;
      },
      async dialogRemoteLx (query) {
        if (this.formDialog1.china.length !== 2) return;
        this.dialog.lxid = await this.post('/wmsCustomerFileWarehouse/getLineByDz', {
          'sheng': this.formDialog1.china[0],
          'cs': this.formDialog1.china[1],
          xlmc: query,
        });
      },
      async dialogChangeLx () {
        this.dialogRemoteLx('');
        this.formDialog1.lxid = '';
      },
      dialogSave () {
        this.VALIDATE('formDialog1', async option => {
          option.sheng = option.china[0];
          option.shi = option.china[1];
          delete option.china;
          if (this.dialog.title === '新增') {
            try {
              let {data} = await this.post('/wmsCustomerFile/save', option);
              let stepDialog = {};
              switch (option.khlx) {
              case '0':
                stepDialog = 'dialogShr';
                break;
              case '1':
                stepDialog = 'dialogCyr';
                break;
              case '2':
                stepDialog = 'dialogCangku';
                break;
              }
              this[stepDialog + 'Open']('add', data);

              this.tableWatch('table');
              this.dialogInit();
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          } else {
            option.id = this.dialog.row.id;
            try {
              await this.put('/wmsCustomerFile/edit', option);
              this.tableWatch('table');
              this.dialogInit();
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
        });
      },

      dialogShrInit () {
        this.dialogShr.row = {};
        this.tableClear('tableShr');
      },
      async dialogShrOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        console.log(row);
        this.dialogShr.row = row;
        this.tableShr.url = '/wmsCustomerFileConsignee/list/' + row.id;
        switch (type) {
        case 'ADD':
          break;
        case 'PUT':
          this.tableWatch('tableShr');
          break;
        }
        this.dialogShr.visible = true;
      },
      tableShrDelete (row) {
        this.$confirm('您将作废该收货地址。', '确认作废？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsCustomerFileConsignee/cancel', {
                ids: [row.id],
              });
              this.tableWatch('tableShr');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableShrActive (row) {
        this.$confirm('您将启用该收货地址。', '确认启用？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsCustomerFileConsignee/activation', {
                ids: [row.id],
              });
              this.tableWatch('tableShr');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableShrSetDefault (row) {
        this.$confirm('您将信息设为默认。', '确认设为默认？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.get('/wmsCustomerFileConsignee/acquiesceIn/' + row.id);
              this.tableWatch('tableShr');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableShrCancelDefault (row) {
        this.$confirm('您将信息取消默认。', '确认取消默认？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.get('/wmsCustomerFileConsignee/removeAcquiesceIn/' + row.id);
              this.tableWatch('tableShr');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      dialogShrSave () {
        this.dialogShrInit();
        this.dialogShr.visible = false;
      },

      dialogShrAddInit () {
        this.dialogShrAdd.title = '新增';
        this.dialogShrAdd.row = {};
        this.formDialogShrAdd = {
          ...this.formDialogShrAdd,
          ...this.ObjectClone(__formShrAdd()),
        };
        this.resetFields('formDialogShrAdd');
      },
      async dialogShrAddOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        switch (type) {
        case 'ADD':
          this.dialogShrAdd.title = '新增';
          break;
        case 'PUT':
          this.dialogShrAdd.title = '修改';
          row.china = [row.sheng, row.shi];
          this.formDialogShrAdd = {
            ...this.formDialogShrAdd,
            ...this.ObjectClone(__formShrAdd(), row),
          };
          this.dialogShrAdd.row = row;
          break;
        }
        this.dialogShrAdd.visible = true;
      },
      dialogShrAddSave () {
        this.VALIDATE('formDialogShrAdd', async option => {
          option.sheng = option.china[0];
          option.shi = option.china[1];
          delete option.china;
          if (this.dialogShrAdd.title === '新增') {
            option.sskhid = this.dialogShr.row.id;
            try {
              await this.post('/wmsCustomerFileConsignee/save', option);
              this.dialogShrAddInit();
              this.tableWatch('tableShr');
              this.dialogShrAdd.visible = false;
            } catch (err) {
              console.log(err);
            }
          } else {
            try {
              option.id = this.dialogShrAdd.row.id;
              await this.post('/wmsCustomerFileConsignee/edit', option);
              for (let index in this.dialogShrAdd.row) {
                if (this.dialogShrAdd.row.hasOwnProperty(index)) {
                  this.dialogShrAdd.row[index] = option[index];
                }
              }
              this.dialogShrAddInit();
              this.tableWatch('tableShr');
              this.dialogShrAdd.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
        });
      },

      dialogCysInit () {
        this.dialogCyr.row = {};
        this.tableClear('tableCyr');
      },
      async dialogCyrOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        this.dialogCyr.row = row;
        this.tableCyr.url = '/wmsCustomerFileCarrier/list/' + row.id;
        switch (type) {
        case 'ADD':
          break;
        case 'PUT':
          this.tableWatch('tableCyr');
          break;
        }
        this.dialogCyr.visible = true;
      },
      tableCyrDelete (row) {
        this.$confirm('您将删除承运车辆。', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let ids;
              await this.post('/wmsCustomerFileCarrier/cancel/', {
                ids: [row.id],
              });
              this.tableWatch('tableCyr');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableCyrActive (row) {
        this.$confirm('您将启用承运车辆。', '确认启用？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let ids;
              await this.post('/wmsCustomerFileCarrier/activation', {
                ids: [row.id],
              });
              this.tableWatch('tableCyr');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      dialogCyrSave () {
        this.dialogCysInit();
        this.dialogCys.visible = false;
      },

      dialogCyrAddInit () {
        this.dialogCyrAdd.title = '新增';
        this.dialogCyrAdd.row = {};
        this.formDialogCyrAdd = {
          ...this.formDialogCyrAdd,
          ...this.ObjectClone(__formCyrAdd()),
        };
        this.resetFields('formDialogCyrAdd');
      },
      async dialogCyrAddOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        switch (type) {
        case 'ADD':
          this.dialogCyrAdd.title = '新增';
          break;
        case 'PUT':
          this.dialogCyrAdd.title = '修改';
          this.formDialogCyrAdd = {
            ...this.formDialogCyrAdd,
            ...this.ObjectClone(__formCyrAdd(), row),
          };
          this.dialogCyrAdd.row = row;
          break;
        }
        this.dialogCyrAdd.visible = true;
      },
      dialogCyrAddSave () {
        this.VALIDATE('formDialogCyrAdd', async option => {
          if (this.dialogCyrAdd.title === '新增') {
            option.sskhid = this.dialogCyr.row.id;
            try {
              await this.post('/wmsCustomerFileCarrier/save', option);
              this.dialogCyrAddInit();
              this.tableWatch('tableCyr');
              this.dialogCyrAdd.visible = false;
            } catch (err) {
              console.log(err);
            }
          } else {
            try {
              option.id = this.dialogCyrAdd.row.id;
              await this.post('/wmsCustomerFileCarrier/edit', option);
              for (let index in this.dialogCyrAdd.row) {
                if (this.dialogCyrAdd.row.hasOwnProperty(index)) {
                  this.dialogCyrAdd.row[index] = option[index];
                }
              }
              this.dialogCyrAddInit();
              this.tableWatch('tableCyr');
              this.dialogCyrAdd.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
        });
      },

      dialogCangkuInit () {
        this.dialogCangku.row = {};
        this.dialogCangku.tree.data = [];
        this.dialogCangku.tree.ids = [];
        this.$refs[this.dialogCangku.tree.ref].setCheckedKeys([]);
      },
      async dialogCangkuOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        let {contentList, ids} = await this.post('/wmsCustomerFileWarehouse/list', {
          sskhid: row.id,
        });
        this.dialogCangku.row = row;
        this.dialogCangku.visible = true;
        let _this = this;
        this.$nextTick(function () {
          _this.dialogCangku.tree.data = contentList;
          _this.$refs[this.dialogCangku.tree.ref].setCheckedKeys(ids);
        });
      },
      async dialogCangkuSave () {
        try {
          await this.post('/wmsCustomerFileWarehouse/save', {
            ids: this.$refs[this.dialogCangku.tree.ref].getCheckedKeys(true),
            id: this.dialogCangku.row.id,
          });
          this.dialogCangku.visible = false;
        } catch (err) {
          console.error(err);
        }
      },
    },
    mounted: function () {
      this.USE('DICTIONARY_customerFile');
      this.tableWatch('table');
    },
    fetch (context) {
      let { store, redirect } = context;
      store.commit('CUSTOMERFILE/SET', China);
    },
  });
</script>

<style scoped lang="scss">
  .s-content{
    width: 100%;
    display: inline-block;
  }

  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>
